namespace RSCore.Files;
public sealed record class TownNPCFile(string Name) : RSFile(Name), IKeyConvertable
{
	public string Content { get; set; } = string.Empty;
	public string NoHome { get; set; } = string.Empty;
	public string LoveSpace { get; set; } = string.Empty;
	public string FarFromHome { get; set; } = string.Empty;
	public string DislikeCrowded { get; set; } = string.Empty;
	public string HateCrowded { get; set; } = string.Empty;
	public string LikeBiome { get; set; } = string.Empty;
	public string LoveBiome { get; set; } = string.Empty;
	public string DislikeBiome { get; set; } = string.Empty;
	public string HateBiome { get; set; } = string.Empty;
	public string LikeNPC { get; set; } = string.Empty;
	public string LoveNPC { get; set; } = string.Empty;
	public string DislikeNPC { get; set; } = string.Empty;
	public string HateNPC { get; set; } = string.Empty;
	public override void Deserialize(JsonValue json)
	{
		Content = json.GetText(nameof(Content));
		NoHome = json.GetText(nameof(NoHome));
		LoveSpace = json.GetText(nameof(LoveSpace));
		FarFromHome = json.GetText(nameof(FarFromHome));
		DislikeBiome = json.GetText(nameof(DislikeBiome));
		HateCrowded = json.GetText(nameof(HateCrowded));
		LikeBiome = json.GetText(nameof(LikeBiome));
		LoveBiome = json.GetText(nameof(LoveBiome));
		DislikeBiome = json.GetText(nameof(DislikeBiome));
		HateBiome = json.GetText(nameof(HateBiome));
		LikeNPC = json.GetText(nameof(LikeNPC));
		LoveNPC = json.GetText(nameof(LoveNPC));
		DislikeNPC = json.GetText(nameof(DislikeNPC));
		HateNPC = json.GetText(nameof(HateNPC));
	}

	public IEnumerable<KeyValuePair<KeyData, string>> Convert()
	{
		var data = new KeyData(Name, EntryType.TownNPCMood, string.Empty);
		yield return new(data with { Property = nameof(Content) }, Content);
		yield return new(data with { Property = nameof(NoHome) }, NoHome);
		yield return new(data with { Property = nameof(LoveSpace) }, LoveSpace);
		yield return new(data with { Property = nameof(FarFromHome) }, FarFromHome);
		yield return new(data with { Property = nameof(DislikeCrowded) }, DislikeCrowded);
		yield return new(data with { Property = nameof(HateCrowded) }, HateCrowded);
		yield return new(data with { Property = nameof(LikeBiome) }, LikeBiome);
		yield return new(data with { Property = nameof(LoveBiome) }, LoveBiome);
		yield return new(data with { Property = nameof(DislikeBiome) }, DislikeBiome);
		yield return new(data with { Property = nameof(HateBiome) }, HateBiome);
		yield return new(data with { Property = nameof(LikeNPC) }, LikeNPC);
		yield return new(data with { Property = nameof(LoveNPC) }, LoveNPC);
		yield return new(data with { Property = nameof(DislikeNPC) }, DislikeNPC);
		yield return new(data with { Property = nameof(HateNPC) }, HateNPC);
	}

	public override void Load(BinaryReader reader)
	{
		Content = reader.ReadString();
		NoHome = reader.ReadString();
		LoveSpace = reader.ReadString();
		FarFromHome = reader.ReadString();
		DislikeCrowded = reader.ReadString();
		HateCrowded = reader.ReadString();
		LikeBiome = reader.ReadString();
		LoveBiome = reader.ReadString();
		DislikeBiome = reader.ReadString();
		HateBiome = reader.ReadString();
		LikeNPC = reader.ReadString();
		LoveNPC = reader.ReadString();
		DislikeNPC = reader.ReadString();
		HateNPC = reader.ReadString();
	}

	public override void Save(BinaryWriter writer)
	{
		writer.Write(Content);
		writer.Write(NoHome);
		writer.Write(LoveSpace);
		writer.Write(FarFromHome);
		writer.Write(DislikeCrowded);
		writer.Write(HateCrowded);
		writer.Write(LikeBiome);
		writer.Write(LoveBiome);
		writer.Write(DislikeBiome);
		writer.Write(HateBiome);
		writer.Write(LikeNPC);
		writer.Write(LoveNPC);
		writer.Write(DislikeNPC);
		writer.Write(HateNPC);
	}

	public override JsonValue Serialize()
	{
		return new JsonObject(
			new(nameof(Content), Content),
			new(nameof(NoHome), NoHome),
			new(nameof(LoveSpace), LoveSpace),
			new(nameof(FarFromHome), FarFromHome),
			new(nameof(DislikeCrowded), DislikeCrowded),
			new(nameof(HateCrowded), HateCrowded),
			new(nameof(LikeBiome), LikeBiome),
			new(nameof(LoveBiome), LoveBiome),
			new(nameof(DislikeBiome), DislikeBiome),
			new(nameof(HateBiome), HateBiome),
			new(nameof(LikeNPC), LikeNPC),
			new(nameof(LoveNPC), LoveNPC),
			new(nameof(DislikeNPC), DislikeNPC),
			new(nameof(HateNPC), HateNPC));
	}

	public override void Write(StreamWriter writer, RSFile? annotation = null)
	{
		var orig = annotation as TownNPCFile;
		writer.WriteProperty(Content, orig?.Content);
		writer.WriteProperty(NoHome, orig?.NoHome);
		writer.WriteProperty(LoveSpace, orig?.LoveSpace);
		writer.WriteProperty(FarFromHome, orig?.FarFromHome);
		writer.WriteProperty(DislikeCrowded, orig?.DislikeCrowded);
		writer.WriteProperty(HateCrowded, orig?.HateCrowded);
		writer.WriteProperty(LikeBiome, orig?.LikeBiome);
		writer.WriteProperty(LoveBiome, orig?.LoveBiome);
		writer.WriteProperty(DislikeBiome, orig?.DislikeBiome);
		writer.WriteProperty(HateBiome, orig?.HateBiome);
		writer.WriteProperty(LikeNPC, orig?.LikeNPC);
		writer.WriteProperty(LoveNPC, orig?.LoveNPC);
		writer.WriteProperty(DislikeNPC, orig?.DislikeNPC);
		writer.WriteProperty(HateNPC, orig?.HateNPC);
	}

	public override void Read(StreamReader reader)
	{
		var properties = reader.ReadProperties();
		Content = properties.GetText(nameof(Content));
		NoHome = properties.GetText(nameof(NoHome));
		LoveSpace = properties.GetText(nameof(LoveSpace));
		FarFromHome = properties.GetText(nameof(FarFromHome));
		DislikeCrowded = properties.GetText(nameof(DislikeCrowded));
		HateCrowded = properties.GetText(nameof(HateCrowded));
		LikeBiome = properties.GetText(nameof(LikeBiome));
		LoveBiome = properties.GetText(nameof(LoveBiome));
		DislikeBiome = properties.GetText(nameof(DislikeBiome));
		HateBiome = properties.GetText(nameof(HateBiome));
		LikeNPC = properties.GetText(nameof(LikeNPC));
		LoveNPC = properties.GetText(nameof(LoveNPC));
		DislikeNPC = properties.GetText(nameof(DislikeNPC));
		HateNPC = properties.GetText(nameof(HateNPC));
	}
}